package com.ifinc.common.db;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-4-23
 * Time: 18:02:11
 * To change this template use File | Settings | File Templates.
 */
public class PropertyUtils {
    private Properties pro = new Properties();
    private static PropertyUtils propertyUtils = null;
    private static Logger log = Logger.getLogger(PropertyUtils.class);

    private static final String name = "db.properties";

    private PropertyUtils(String filename) {
        try {
            if (filename == null)
                filename = name;
            pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename));
        } catch (IOException e) {
            log.error(e);
            throw new RuntimeException(e.getMessage());
        } finally {
        }
    }

    public static PropertyUtils getInstance(String path) {
        if (propertyUtils == null) {
            synchronized (PropertyUtils.class) {
                if (propertyUtils == null) {
                   propertyUtils = new PropertyUtils(path);
                }
            }
        }
        return propertyUtils;
    }

    public String getValue(String key) {
        return (String) pro.get(key);
    }

    public static void main(String[] args) throws Exception {
    }

}
